﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using GeneralDFS.Common;
using GeneralDFS.DataEntity.Config;
using GeneralDFS.DataEntity.IO;

namespace GeneralDFS.BusinessLogical.IO
{
    public class Block
    {
        public static FileStream CreateBlockFile(Guid guid,FsDir fsDir)
        {
            throw new NotImplementedException();
        }

        public static void SaveMetaData(FsDir fsDir, Guid guid,byte[] metaData)
        {
            FileStream newMetaData = fsDir.CreateMetaFile(guid);
            newMetaData.Write(metaData, 0, metaData.Length);
            newMetaData.Flush(true);
            newMetaData.Close();
        }

        public static void SaveMetaData(FsDir fsDir, FileBlockMetaData metaData, Guid guid)
        {
            FileStream newMetaData = fsDir.CreateMetaFile(guid);
            Byte[] metaDataBytes = SerializeHelper.GetBytes(metaData);
            newMetaData.Write(metaDataBytes, 0, metaDataBytes.Length);
            newMetaData.Flush(true);
            newMetaData.Close();
        }
        public static bool CheckIsBlock(string fileName)
        {
            if (fileName.StartsWith("blk_"))
                return true;
            return false;
        }
        public static bool CheckIsBlock(FileInfo fileInfo)
        {
            return CheckIsBlock(fileInfo.Name);
        }

        public static FileStream GetFreeDir(DataNodeConfig dataNodeConfig, Guid guid)
        {
            throw new NotImplementedException();
        }
    }
}